cmake_minimum_required(VERSION 3.27)
#project(p1_hello C)
# 修改为动态指定项目目录
# 获取CMAKE文件的目录名字称赋值给ProjectId
get_filename_component(ProjectId ${CMAKE_CURRENT_SOURCE_DIR} NAME)
# 目录名字中有空格替换为下划线
string(REPLACE " " "_" ProjectId ${ProjectId})
project(${ProjectId} C)

set(CMAKE_C_STANDARD 11)

#add_executable(p1_hello main.c)

# 修改为
# 获取 CMAKE_CURRENT_SOURCE_DIR 目录下的所有.c文件，存储在files中
file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
# 遍历files
foreach (file ${files})
    get_filename_component(name ${file} NAME)
    # 每个.c文件都添加为可执行程序
    add_executable(${name} ${file})
endforeach ()